package com.example.myapplication;

import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.AppCompatTextView;

import java.util.Objects;

public class MainActivity_denglu extends AppCompatActivity {

    private AppCompatTextView mainTextView;
//    private AppCompatImageView mainImageView;图片


    private AppCompatAutoCompleteTextView accountTextView;
    private AppCompatAutoCompleteTextView passwordTextView;
    private AppCompatCheckBox showCheckBox;
    private AppCompatAutoCompleteTextView confirmTextView;
    private AppCompatRadioButton boyRadioButton;
    private AppCompatRadioButton girlRadioButton;
    private AppCompatTextView registerTextView;

    //定义TextView变量
  //  private TextView mainTextView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        accountTextView=findViewById(R.id.accountTextView);
        passwordTextView=findViewById(R.id.passwordTextView);
        showCheckBox=findViewById(R.id.showCheckBox);
        confirmTextView=findViewById(R.id.confirmTextView);
        boyRadioButton=findViewById(R.id.boyRadioButton);
        girlRadioButton=findViewById(R.id.girlRadioButton);
        registerTextView=findViewById(R.id.registerTextView);

        showCheckBox.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b){
                passwordTextView.setInputType(InputType.TYPE_CLASS_TEXT);
                confirmTextView.setInputType(InputType.TYPE_CLASS_TEXT);
            }else {
                passwordTextView.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                confirmTextView.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
        });
        registerTextView.setOnClickListener(view -> {
            String account = Objects.requireNonNull(accountTextView.getText().toString());
            if (account.isEmpty()){
                Toast.makeText(MainActivity_denglu.this,"请输入账号",Toast.LENGTH_LONG).show();
                return;
            }
            String password = Objects.requireNonNull(passwordTextView.getText().toString());
            String confirm = Objects.requireNonNull(confirmTextView.getText().toString());
            if (password.isEmpty()||confirm.isEmpty()) {
                Toast.makeText(MainActivity_denglu.this, "请输入密码", Toast.LENGTH_LONG).show();
                return;
            }
            if (password.length()<8){
                Toast.makeText(MainActivity_denglu.this,"密码长度必须要超过8位",Toast.LENGTH_LONG).show();
            }
            if (!password.equals(confirm)){
                Toast.makeText(MainActivity_denglu.this,"两次输入密码不一致",Toast.LENGTH_LONG).show();
            }
            Log.d("Register","账号："+account);
            Log.d("Register","密码："+password);
            Log.d("Register","性别："+(boyRadioButton.isChecked()?"男":"女"));
        });

//图片
//        mainImageView = findViewById(R.id.mainImageView);
//        Glide.with(this).load("http://t14.baidu.com/it/u=3583042448,1749746744&fm=224&app=112&f=JPEG?w=500&h=500")
//                .into(mainImageView);

        //设置布局文件（绑定布局文件）
        //setContentView(R.layout.activity_main20221030);
        //实例化控件 findViewById
       /* mainTextView=findViewById(R.id.mainTextView);
        //点击事件
        mainTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // 相应单机事件，在此处写单机之后需要执行代码
                mainTextView.setTextColor(Color.BLACK);//文字颜色
                mainTextView.setText("鸡你太美");
            }
        });*/

    }

}
